﻿using UnityEngine;
using System.Collections;

public class GyroController : MonoBehaviour
{
    void Start()
    {
        if (Application.platform == RuntimePlatform.Android)
        {
            Input.gyro.enabled = true;
            Screen.sleepTimeout = SleepTimeout.NeverSleep;
            Input.gyro.updateInterval = 60f;
        }
    }

    void Update()
    {
        transform.localRotation = CameraRotation();
    }

    Quaternion CameraRotation()
    {
        Quaternion input = Input.gyro.attitude;
        input = Quaternion.Euler(90, 0, 0) * (new Quaternion(-input.x, -input.y, input.z, input.w));
        return input;
    }
}